package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDTO;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级管理")
public class NursingLevelController {

    @Autowired
    private NursingLevelService nursingLevelService;

    //条件分页查询
    @GetMapping("/listByPage")
    @ApiOperation(value = "分页查询护理等级信息")
    public ResponseResult<PageResponse<NursingLevelVO>> selectByPage(
            @ApiParam(value = "护理等级名称") String name,
            @ApiParam(value = "页码") Integer pageNum,
            @ApiParam(value = "每页数量") Integer pageSize,
            @ApiParam(value = "状态") Integer status){
        PageResponse<NursingLevelVO> nursingLevelVOPageResponse = nursingLevelService.selectByPage(name, pageNum, pageSize, status);
        return ResponseResult.success(nursingLevelVOPageResponse);
    }

    //查询所有护理等级信息
    @GetMapping("/listAll")
    @ApiOperation(value = "查询所有护理等级信息")
    public ResponseResult<List<NursingLevelVO>> selectAll(){
        List<NursingLevelVO> all = nursingLevelService.selectAll();
        return ResponseResult.success(all);
    }

    //根据id查询
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理等级信息")
    public ResponseResult<NursingLevelVO> selectById(@ApiParam(value = "护理等级id")@PathVariable Long id){
        NursingLevelVO nursingLevelVO = nursingLevelService.selectById(id);
        return ResponseResult.success(nursingLevelVO);
    }

    //启用/禁用
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用/禁用护理等级信息")
    public ResponseResult enableOrDisable(@ApiParam(value = "护理等级id")@PathVariable Long id,
                                          @ApiParam(value = "护理等级状态")@PathVariable Integer status){
        nursingLevelService.enableOrDisable(id, status);
        return ResponseResult.success();
    }

    //删除
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "根据id删除护理等级信息")
    public ResponseResult removeNursingLevel(@ApiParam(value = "护理等级id")@PathVariable Long id){
        nursingLevelService.removeNursingLevel(id);
        return ResponseResult.success();
    }

    //添加护理等级信息
    @PostMapping("/insert")
    @ApiOperation(value = "添加护理等级信息")
    public ResponseResult addNursingLevel(
            @ApiParam(value = "护理等级信息")
            @RequestBody NursingLevelDTO nursingLevelDto){
        nursingLevelService.addNursingLevel(nursingLevelDto);
        return ResponseResult.success();
    }

    //修改护理等级信息
    @PutMapping("/update")
    @ApiOperation(value = "修改护理等级信息")
    public ResponseResult updateNursingLevel(@ApiParam(value = "护理等级信息")@RequestBody NursingLevelDTO nursingLevelDto){
        nursingLevelService.updateNursingLevel(nursingLevelDto);
        return ResponseResult.success();
    }

}
